<?php
 
class ImageHelper {
    
    /**
     * Return the web path for the copied file
     */
    public static function saveLocalVersionOfImage($sourceUrl) {
        $sourceUrlChunks = explode(".", $sourceUrl);
        $fileType = $sourceUrlChunks[count($sourceUrlChunks) - 1];
        
        $uniqueFileId = md5($sourceUrl);
        $filename = $uniqueFileId . "." . $fileType;
        
        $serverFile = sfConfig::get('sf_upload_dir') . '/' . $filename;
        $webFile = '/uploads/' . $filename;
        
        copy($sourceUrl, $serverFile);
        
        return $webFile;
    }
    
}